<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>客户关系管理及报关单统计系统</title>
<!--#include file="lib/plugins.asp"-->
<!--#include file="lib/js-jquery-validate-lib.asp"-->
<style type="text/css">
	.yform .type-check label {
		width: 6em;
		display: inline-block;
	}
   .subcl,.subcr,.subc {
    padding-bottom: 100em;
    margin-bottom: -100em;
  }
	h6 {
		background: #600;
		color: white;
		font-weight: bold;
		padding: 5px 10px;
	}
	#tablelist{
		font-family:宋体;
	}
</style>
<script type="text/javascript">
	$(function() {
		$("#form1").validationEngine();
		$("input:checked").next().next().prop("disabled",false)
		$("input[name='post']").click(function(){
			if($(this).prop("checked")){
				$(this).next().next().prop("disabled",false)
			}else{
				$(this).next().next().prop("disabled",true)
			}
		});
	});
</script>
<!--#include file="lib/js-google-analytics.asp"-->
</head>
<%
if not CheckPostFlag(session("aaPostflag"),0,15) then call JumpErrorPage(2)
id=request("id")
submit=request("submit")
If submit<>"" Then
	conn.BeginTrans
	username=LCase(request("username"))
	password=request("password")
	empe=request("empe")
	dept=request("dept")
	captain=request("captain")
	active=request("active")
	if captain="" then captain=0 else captain=1
	if active="" then active=0 else active=1
	if submit="新增" then
		sql="insert into crm_empe(username,[password],empe,dept,captain,active) values('"&username&"','"&password&"','"&empe&"',"&dept&","&captain&","&active&")"
		'response.write(sql)
		'response.end
		newuserid=ExecuteCommand(sql,true)
	end if
	if submit="保存" then
		sql="update crm_empe set username='"&username&"',[password]='"&password&"',empe='"&empe&"',dept="&dept&",captain="&captain&",active="&active&" where id="&id
		call ExecuteCommand(sql,false)
		sql="delete from crm_permit where empe="&id
		call ExecuteCommand(sql,false)
		newuserid=id
	end if
	for i=1 to request.form("post").count
		post=request.form("post")(i)
		flag=request.form("flag")(i)
		sql="insert into crm_permit(empe,post,flag) values("&newuserid&","&post&","&flag&")"
		call ExecuteCommand(sql,flase)
	next
	if err.number=0 then 
		conn.CommitTrans  '如果没有conn错误，则执行事务提交
	else
		conn.RollbackTrans '否则回滚
		'回滚后的其他操作
		'strerr=err.Description
		url=request.ServerVariables("http_host")&request.ServerVariables("url")
		Response.Write "数据库错误！<br /><font color=red>Error # " & CStr(Err.Number) & "<br />" & Err.Description & "<br />Source: " & Err.Source &"<br />错误页面："&url&"</font><br />"
		Response.End
	end if

end if
if id<>"" then
	Set rs = Server.CreateObject("ADODB.Recordset")
	sql = "select crm_empe.*,crm_permit.post,crm_permit.flag from crm_empe left join crm_permit on crm_empe.id=crm_permit.empe where id="&id
	rs.Open sql,conn,1,1
	username=rs("username")
	password=rs("password")
	empe=rs("empe")
	dept=rs("dept")
	captain=rs("captain")
	active=rs("active")
	aaFlag=rs.getrows(,,array("post","flag"))
	rs.close
	set rs=nothing
' else
	' dim aaFlag(1,0)
	' aaFlag(0,0)=null
	' aaFlag(1,0)=null
end if
%>
<body>
<!--#include file="lib/header.asp"-->
<!--#include file="lib/nav.asp"-->
<div id="main">
<!--#include file="lib/col1.asp"-->
<!--#include file="lib/col2.asp"-->
	<div id="col3" role="main">
		<div id="col3_content" class="clearfix">
			<form id="form1" name="form1" method="post" class="yform" role="application">
				<div class="subcolumns equalize">
					<div class="c50l">
						<div class="subcl">
							<h6>基本资料</h6>
							<div class="type-text">
								<label for="username">用户名*</label>
								<input name="username" class="validate[required,minSize[3],maxSize[10],custom[onlyLcaseLetter]]" maxlength="10" id="username" type="text" value="<%=username%>" />
							</div>
							<div class="type-text">
								<label for="password">密码*</label>
								<input name="password" class="validate[required,minSize[6],maxSize[10],custom[onlyPassword]]" maxlength="10" id="password" type="password" value="<%=password%>" />
							</div>
							<div class="type-text">
								<label for="empe">姓名*</label>
								<input name="empe" class="validate[required,minSize[2],maxSize[4]]" maxlength="4" id="empe" type="text" value="<%=empe%>" />
							</div>
							<div class="type-select">
								<label for="dept">所属组*</label>
								<select id="dept" name="dept">
									<%
										Set rs_dept = Server.CreateObject("ADODB.Recordset")
										sql = "SELECT * FROM crm_dept order by id"
										rs_dept.Open sql,conn,1,1
										do while not rs_dept.eof
									%>
									<option value="<%=rs_dept("id")%>" <%if rs_dept("id")=dept then response.write("selected='selected'")%>><%=rs_dept("dept")%></option>
									<%
											rs_dept.movenext
										loop
										rs_dept.close
										set rs_dept=nothing
									%>
								</select>
							</div>
							<div class="type-check">
								<input name="captain" id="captain" type="checkbox" value="true" <%if captain then response.write("checked='checked'")%> />
								<label for="captain">组长</label>
							</div>
							<div class="type-check">
								<input name="active" id="active" type="checkbox" value="true" <%if active then response.write("checked='checked'")%> />
								<label for="active">激活用户</label>
							</div>
						</div>
					</div>
					<div class="c50r">
						<div class="subcr">
							<h6>权限管理</h6>
							<%
								Set rs_post = Server.CreateObject("ADODB.Recordset")
								sql_post = "SELECT *  FROM crm_post order by id"
								rs_post.Open sql_post,conn,1,1
								do while not rs_post.eof
							%>
							<div class="type-check">
								<input name="post" id="post<%=rs_post("id")%>" type="checkbox" value="<%=rs_post("id")%>" <%if CheckPost(aaFlag,rs_post("id")) then response.write("checked='checked'")%> />
								<label for="post<%=rs_post("id")%>"><%=rs_post("post")%></label>
								<select name="flag" disabled="disabled">
									<option value="1" <%if CheckPost(aaFlag,rs_post("id")) and GetFlagValue(aaFlag,rs_post("id"))=1 then response.write("selected")%>>查询</option>
									<option value="2" <%if CheckPost(aaFlag,rs_post("id")) and GetFlagValue(aaFlag,rs_post("id"))=2 then response.write("selected")%>>查询、查看</option>
									<option value="3" <%if CheckPost(aaFlag,rs_post("id")) and GetFlagValue(aaFlag,rs_post("id"))=3 then response.write("selected")%>>查询、查看、添加</option>
									<option value="4" <%if CheckPost(aaFlag,rs_post("id")) and GetFlagValue(aaFlag,rs_post("id"))=4 then response.write("selected")%>>查询、查看、添加、编辑</option>
									<option value="5" <%if CheckPost(aaFlag,rs_post("id")) and GetFlagValue(aaFlag,rs_post("id"))=5 then response.write("selected")%>>查询、查看、添加、编辑、删除</option>
									<option value="15" <%if CheckPost(aaFlag,rs_post("id")) and GetFlagValue(aaFlag,rs_post("id"))=15 then response.write("selected")%>>管理员</option>
								</select>
							</div>
							<%
									rs_post.movenext
								loop
								rs_post.close
								set rs_post=nothing
							%>
						</div>
					</div>
				</div>
				<div  class="type-button">
					<%if id="" then%>
					<input type="submit" name="submit" value="新增" />
					<%end if%>
					<%if id<>"" and id<>1 then%>
					<input type="submit" name="submit" value="保存" />
					<%end if%>
				</div>
			</form>
			<table id="tablelist" class="full">
				<thead>
					<tr><th colspan="6" scope="col">用户明细</th></tr>
				</thead>
				<tbody>
					<tr>
						<th scope="col">用户名</th>
						<th scope="col">姓名</th>
						<th scope="col">所属组</th>
						<th scope="col">组长</th>
						<th scope="col">状态</th>
						<th scope="col">权限</th>
					</tr>
					<%
						sql = "select crm_empe.*,crm_dept.dept as deptname from crm_empe,crm_dept where crm_empe.dept=crm_dept.id"
						Set rs = Server.CreateObject("ADODB.Recordset")
						rs.Open sql,conn,1,1
						do while not rs.eof
					%>
					<tr>
						<th class="sub" scope="row"><a href="username.asp?id=<%=rs("id")%>"><%=rs("username")%></a></th>
						<td><%=rs("empe")%></td>
						<td><%=rs("deptname")%></td>
						<td><%if rs("captain") then response.write("√")%></td>
						<td><%if rs("active") then response.write("激活")%></td>
						<td>
						<%
							Set rs_flag = Server.CreateObject("ADODB.Recordset")
							sql_flag="SELECT crm_post.post,crm_flag.flag from crm_permit,crm_post,crm_flag where crm_permit.post=crm_post.id and crm_permit.flag=crm_flag.id and empe="&rs("id")
							rs_flag.Open sql_flag,conn,1,1
							do while not rs_flag.eof
								response.write(FillSpace(rs_flag("post"),12)&"："&rs_flag("flag")&"<br />")
								rs_flag.movenext
							loop
							rs_flag.close
							set rs_flag=nothing
						%>
						</td>
					</tr>
					<%
							rs.movenext
						loop
						rs.close
						set rs=nothing
					%>
				</tbody>
			</table>
		</div>
	</div>
</div>
<!--#include file="lib/footer.asp"-->
</body>
</html>
<!--#include file="lib/connclose.asp"-->

